package chapter7.whatIsThis;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		System.out.println("请输入车辆类型：1、小汽车 2、大巴车 3、卡车 更多车辆类型开发中！");
		int vehicleType=scanner.nextInt();
		System.out.println("请输入行驶公里数");
		int distance=scanner.nextInt();
		Vehicle vehicle=null;
		switch (vehicleType){
			case 1:
				vehicle=new car();
				break;
			case 2:
				vehicle=new bus();
				break;
			case 3:
				System.out.println("请输入卡车载重量（吨）");
				double weight=scanner.nextDouble();
				vehicle=new truck(weight);
				break;
			default:
				System.out.println("无效的车辆类型!");
				return;
		}
		double fare=vehicle.fee(distance);
		System.out.println("收费金额："+fare+"元");
		System.out.println("请在键盘输入1以确认信息");
		while(true){
			Scanner sc=new Scanner(System.in);
			int a= sc.nextInt();
			if(a==1){
				System.out.println("信息确认成功！");
				System.out.println("付费成功，一路顺风！");
				break;
			}
			else {
				System.out.println("信息确认失败！请重新确认信息");
			}
		}
	}
}

class Vehicle{
	String license;
	String type;
	double price;
	public Vehicle(String type,double price){
		this.type=type;
		this.price=price;
	}
	public double fee(int distance){
		return distance*price;
	}
}

class car extends Vehicle{
	public car(){
		super("小汽车",0.5);
	}
	@Override
	public double fee(int distance){
		return distance*price;
	}
}

class bus extends Vehicle{
	public bus(){
		super("大巴车",1);
	}
	@Override
	public double fee(int distance){
		return distance*price;
	}
}

class truck extends Vehicle{
	private final double weight;
	public truck(double weight){
		super("卡车",0);
		this.weight=weight;
	}
	@Override
	public double fee(int distance){
		return weight*distance*5;
	}
}